window.onload = function(){
	var username = '钟驰宇';
	var codemirror , result;
	//codemirror

	(function init(){
		codemirror = CodeMirror(document.getElementById('codearea'),{
			mode:'text/html',
			lineNumbers:true,
			onChange:onCodeChange,
		});
		result = document.getElementById('result');
		codemirror.setValue(username);
		result.innerHTML = username;
		//Add event listener
		document.getElementById('finished').onclick = varify;
	})();


	//event listener on code change
	function onCodeChange(){
		result.innerHTML = codemirror.getValue();
	}

	function varify(){
		var b = result.getElementsByTagName('B')[0];
		if( b && b.style.color === 'red'){
			if( b.innerHTML === username ){
				alert('sample url or open new window');
				return;
			}
			alert('姓名怎么改变了?');
			return;
		}
		alert('代码不正确');
		return;
	}
};
